﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WeChatSubscribe.aspx.cs" Inherits="Page_日常工作_WeChatSubscribe" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="/Com/JS/easyUi/themes/icon.css" rel="stylesheet" />
    <link href="/Com/JS/easyUi/themes/default/easyui.css" rel="stylesheet" />
    <link href="/Com/JS/formValidator/css/template.css" rel="stylesheet" />
    <link href="/Com/JS/formValidator/css/validationEngine.jquery.css" rel="stylesheet" />
    <link href="/Com/CSS/default.css" rel="stylesheet" />
    <script src="/Com/JS/jquery-1.8.2.js"></script>
    <script src="/Com/JS/easyUi/jquery.easyui.min.js"></script>
    <script src="/Com/JS/Common.js"></script>
    <script src="/Com/JS/jquery.form.js"></script>
    <script src="/Com/JS/formValidator/js/jquery.validationEngine.js"></script>
    <script src="/Com/JS/formValidator/js/languages/jquery.validationEngine-zh_CN.js"></script>
    <%--layui--%>
    <link href="../../Com/layui/css/layui.css" rel="stylesheet" />
    <script src="../../Com/layui/layui.js"></script>
    <script type="text/javascript">
        var optionProductList = {};
        var IsCheckFlag = true;
        $().ready(function () {
            var option = {
                iconCls: 'icon-save',
                idField: 'IDPlus',
                nowrap: false,
                fit: true,
                striped: true,
                useRp: true,
                pageList: [1, 10, 15, 20],
                pageSize: 10,
                url: '/Handler/SoultionHandler.ashx?action=GetWeChatTable',
                loadMsg: '数据装载中......',
                sortName: 'AddTime',
                sortOrder: 'desc',
                queryParams: {},
                singleSelect: true,
                columns: [[
                    {
                        title: "操作",
                        field: "opt",
                        width: 150,
                        align: 'center',
                        formatter: function (value, rowData, rowIndex) {
                            var strOption = "";
                            strOption += '<a href="#" style="text-decoration:none;color:blue" onclick="Edit(\'' + rowData.Id + '\',\'' + rowData.ISSendWeChat1 + '\',\'' + rowData.PositionRoles + '\',\'' + rowData.Category + '\',\'' + rowData.CardID + '\');">修改</a>&nbsp&nbsp';
                            strOption += '<a href="#" style="text-decoration:none;color:blue" onclick="SetInterface(\'' + rowData.Id + '\',\'' + rowData.Category + '\');">设置接口权限</a>&nbsp&nbsp';
                            return strOption;
                        }
                    },
                    { title: '主键', field: 'Id', sortable: true, align: 'center', width: 120, hidden: true },
                    { title: '昵称', field: 'Nickname', align: 'center', width: 150 },
                    { title: 'OpenId', field: 'Openid', align: 'center', width: 250 },
                    {
                        title: '头像', field: 'Headimgurl', align: 'center', width: 140, formatter: function (value, rowData, rowIndex) {
                            return "<img style='width:60px;height:60px;' src='" + value + "'  />";
                        }
                    },
                {
                    title: '是否推送信息', field: 'ISSendWeChat1', align: 'center', width: 100, formatter: function (value, rowData, rowIndex) {
                        if (value == "1") {
                            return "推送";
                        }
                        else {
                            return "不推送";
                        }
                    }
                }, {
                    title: '角色', field: 'PositionRolesval', align: 'center', width: 250
                }, {
                    title: '工号', field: 'CardID', align: 'center', width: 100
                }
                ]],
                pagination: true,
                rownumbers: true,
                toolbar: "#divToolBar",
                onSortColumn: function (sort, order) {
                    var queryParams = $('#dataList').datagrid('options').queryParams;
                    queryParams.SortName = sort;
                    queryParams.SortOrder = order;
                }
            };

            option.queryParams = { RP: option.pageSize };
            $("#dataList").datagrid(option);
            //分页实现
            var p = $('#dataList').datagrid('getPager');
            if (p) {
                $(p).pagination({
                    displayMsg: '当前显示从{from}到{to}共{total}记录',
                    beforePageText: "第",
                    afterPageText: "共 {pages}",
                    onBeforeRefresh: function (pageNumber, pageSize) {
                        $(this).pagination('loading');
                    },
                    onChangePageSize: function () {
                        var queryParams = $('#dataList').datagrid('options').queryParams;
                        queryParams.RP = $(p).pagination('options').pageSize;
                    },
                    onRefresh: function () {
                    },
                    onSelectPage: function (pageNumber, pageSize) {
                        var queryParams = $('#dataList').datagrid('options').queryParams;
                        queryParams.Page = pageNumber;
                        $("#dataList").datagrid('reload');
                    }
                });
            }

            var val_payPlatform = $('input[name="txtEditName"]:checked ').val();
            //修改产品标签异步表单
            var optionEditTag = {
                dataType: 'text',
                beforeSubmit: showRequest,
                error: showError,
                success: showEditResponse,
                data: { txtEditName: val_payPlatform }
            };
            $('#formEditTag').ajaxForm(optionEditTag);


            //产品详细列表
            optionProductList = {
                iconCls: 'icon-save',
                idField: 'id',
                nowrap: false,
                fit: true,
                striped: true,
                useRp: true,
                url: '',
                loadMsg: '数据装载中......',
                queryParams: {},
                singleSelect: false,
                columns: [[
                    { title: '编号', field: 'id', sortable: true, align: 'center', width: 110, checkbox: true },
                    { title: '类别名称', field: 'typeName', sortable: true, align: 'center', width: 140 },
                ]],
                rownumbers: true,
                onLoadSuccess: function (row) {//当表格成功加载时执行               
                    var rowData = row.rows;
                    var index = 0;
                    var skus = $("#skus").val();
                    $.each(rowData, function () {//遍历JSON
                        if (skus.indexOf(rowData[index].id) > -1) {
                            $("#dataListProduct").datagrid("selectRecord", rowData[index].id); //如果数据行为已选中则选中改行
                        } else {
                            $("#dataListProduct").datagrid("unselectRow", index);
                        }
                        index++;
                    });
                },
                onClickCell: function (rowIndex, field, value) {
                    IsCheckFlag = false;
                },
                onSelect: function (rowIndex, rowData) {
                    if (!IsCheckFlag) {
                        IsCheckFlag = true;
                        $("#dataListProduct").datagrid("unselectRow", rowIndex);
                    }
                },
                onUnselect: function (rowIndex, rowData) {
                    if (!IsCheckFlag) {
                        IsCheckFlag = true;
                        $("#dataListProduct").datagrid("selectRow", rowIndex);
                    }
                }
            };

            //选择产品dialog设置
            $("#dialogSetProduct").dialog({
                title: "选择类别",
                width: 800,
                height: 550,
                buttons: [{
                    id: 'btnSetProduct',
                    text: '确定',
                    iconCls: 'icon-ok',
                    handler: function () {
                        //提交
                        var mySelect = $("#dataListProduct").datagrid("getSelections");
                        if (mySelect == null || mySelect.length <= 0) {
                            alert("请选择类别!");
                            return;
                        }
                        var skus = "";
                        for (var i = 0; i < mySelect.length; i++) {
                            skus = skus + mySelect[i].id + ",";
                        }
                        skus = skus.substring(0, skus.length - 1);
                        var idplus = $("#idplus").val();
                        if (confirm("确定授予所选类别么？")) {
                            var currentDate = new Date();
                            $.get('/Handler/ProblemsTypeHandler.ashx?action=AddWechartType', { NowDate: currentDate, Skus: skus, IDPlus: idplus }, function (data) {
                                var result = GetResult(data);
                                if (result.IsSuccess) {
                                    alert(result.Message);
                                } else {
                                    if (result.message != "") {
                                        alert(result.message);
                                    }
                                }
                                $("#dataListProduct").datagrid("reload");
                                $("#dataList").datagrid('reload');
                            });
                        }
                        $("#dataListProduct").datagrid("unselectAll");
                        $("#dialogSetProduct").dialog("close");
                        $("#dataList").datagrid('reload');
                    }
                },
                {
                    text: '关闭',
                    iconCls: 'icon-cancel',
                    handler: function () {
                        $("#dialogSetProduct").dialog("close");
                    }
                }]
            });


            //修改产品标签
            $("#dialogEditTag").dialog({
                title: "修改",
                width: 700,
                height: 420,
                buttons: [{
                    id: 'btnEditTag',
                    text: '确定',
                    iconCls: 'icon-ok',
                    handler: function () {
                        //提交表单
                        if ($("#formEditTag").validationEngine('validate') == true) {
                            $("#btnEditTag").linkbutton('disable');
                            $("#formEditTag").submit();
                        }
                    }
                },
                    {
                        text: '取消',
                        iconCls: 'icon-cancel',
                        handler: function () {
                            $("#dialogEditTag").dialog("close");
                        }
                    }]
            });
        });



        //表单提交前
        function showRequest(formData, jqForm, options) {
            return true;
        }
        //表单提交出错
        function showError(data) {
            alert('提交出错！');
        }

        //修改产品标签成功
        function showEditResponse(data, status) {
            var result = GetResult(data);
            if (result.IsSuccess) {
                $("#dialogEditTag").dialog('close');
                document.getElementById("formEditTag").reset();
                $("#dataList").datagrid('reload');
                alert(result.Message);
            } else {
                if (result.Message != "") {
                    alert(result.Message);
                }
            }
            $("#btnEditTag").linkbutton('enable');
        }

        //查询
        function Query() {
            var search = "";
            $('#divToolBar').find(":selected,select,textarea,:hidden,:checkbox,:password").each(function () {
                search = search + this.id + "&" + this.value + "^";
            });
            $('#divToolBar').find(":input").each(function () {
                search = search + this.name + "&" + this.value + "^";
            });
            var queryParams = $('#dataList').datagrid('options').queryParams;
            $('#dataList').datagrid('options').page = 1;
            queryParams.Page = 1;
            queryParams.Query = search;
            var gp = $('#dataList').datagrid('getPager');
            if (gp) {
                gp.pagination('options').pageNumber = 1;
                gp.pagination('loading');
            }
            $("#dataList").datagrid('reload'); //刷新
        }

        //修改产品标签
        function Edit(idplus, ISSendWeChat1, PositionRoles,category,cardId) {
            $("input[name='txtEditName']").each(function () {
                if ($(this).val() == ISSendWeChat1) {
                    $(this).attr("checked", true);
                }
            });
            $("#selectProductCategory").val(PositionRoles);
            $("#selectCategory").val(category);
            $("#txtEditCardId").val(cardId);
            $("#formEditTag").attr("action", "/Handler/SoultionHandler.ashx?action=EditWeChatInfo&IDPlus=" + idplus);
            $("#dialogEditTag").dialog("open");

        }

        //设置接口
        function SetInterface(idplus, interfaces) {
            $("#idplus").val(idplus);
            $("#skus").val(interfaces);
            optionProductList.url = "/Handler/ProblemsTypeHandler.ashx?action=Getdt_type_listTable";
            $("#dataListProduct").datagrid(optionProductList);
            $("#dialogSetProduct").dialog("open");

        }

    </script>

    <script>
        layui.use('laydate', function () {

            var laydate = layui.laydate;

            var start = {
                min: '2000-01-01 00:00:00'
              , max: '2099-06-16 23:59:59'
              , istoday: true
                //, istime: false
              , festival: true
              , choose: function (datas) {
                  end.min = datas; //开始日选好后，重置结束日的最小日期
                  end.start = datas //将结束日的初始值设定为开始日
              }

            };

            var end = {
                min: '2000-01-01 00:00:00'
              , max: '2099-06-16 23:59:59'
              , istoday: true
                , festival: true
              , choose: function (datas) {
                  start.max = datas; //结束日选好后，重置开始日的最大日期
              }
            };
            document.getElementById('LAY_demorange_s').onclick = function () {
                start.elem = this;
                laydate(start);

            }
            document.getElementById('LAY_demorange_e').onclick = function () {
                end.elem = this
                laydate(end);
            }

        });


        layui.use('layer', function () { //独立版的layer无需执行这一句
            var $ = layui.jquery, layer = layui.layer; //独立版的layer无需执行这一句

            //触发事件
            var active = {
                notice: function () {
                    //示范一个公告层
                    layer.open({
                        type: 1
                      , title: false //不显示标题栏
                      , closeBtn: false
                      , area: '300px;'
                      , shade: 0.8
                      , id: 'LAY_layuipro' //设定一个id，防止重复弹出
                      , btn: ['取消']
                      , moveType: 1 //拖拽模式，0或者1
                      , content: '<div class="laycontent" style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">数据拉取中！</div>'
                      , success: function (layero) {
                          var btn = layero.find('.layui-layer-btn');
                          btn.css('text-align', 'center');
                      }
                    });
                }
            };

            $('.layui-btn').on('click', function () {
                var othis = $(this), method = othis.data('method');
                active[method] ? active[method].call(this, othis) : '';

                $.ajax({
                    url: "/Handler/SoultionHandler.ashx?action=GetSubscribe", async: true, success: function (result) {
                        $(".layui-layer-btn0").text("关闭");
                        $(".laycontent").text("数据拉取完成！");
                        Query();
                    }
                });

            });

        });

    </script>
</head>
<body class="easyui-layout" style="height: 95%; overflow: hidden; border: none;">
    <div id="divToolBar" style="padding: 5px; height: auto">
        <div style="margin-bottom: 5px">
            <button data-method="notice" class="layui-btn">拉取微信用户</button>
        </div>
        <div>
            <div class="layui-form-pane" style="margin-top: 15px;">
                <div class="layui-form-item">
                    <label class="layui-form-label" style="padding: 1px 15px;">范围选择：</label>
                    <div class="layui-input-inline">
                        <input class="inline laydate-icon" style="padding-left: 10px;" placeholder="开始日" id="LAY_demorange_s" name="txtStartDate" />
                    </div>
                    <div class="layui-input-inline">
                        <input class="inline laydate-icon" style="padding-left: 10px;" placeholder="截止日" id="LAY_demorange_e" name="txtEndDate" />
                    </div>

                    &nbsp
                   关键字：
            <input id="txtKeyWords" name="txtKeyWords" type="text" class="txt01" style="width: 100px;" />
                    &nbsp

            <a id="btnSearch" href="javascript:void(0);" iconcls="icon-search" class="easyui-linkbutton" onclick="Query()">查询</a>
                </div>
            </div>

        </div>
    </div>
    <div region="center" border="false" style="margin-left: 5px; margin-top: 3px">
        <table id="dataList">
        </table>
    </div>

    <%-- 编辑问题类型 --%>
    <div id="dialogEditTag" class="easyui_dialog" style="padding: 10px 10px;" closed="true">
        <form id="formEditTag" action="/Handler/SoultionHandler.ashx?action=EditWeChatInfo" class="fm" method="post">
            <table cellpadding="3" cellspacing="1" style="width: 100%; margin: 0px auto; line-height: 26px;">
                <tr>
                    <td class="td-first">推送微信消息：</td>
                    <td class="td-second">
                        <input name="txtEditName" type="radio" value="0" />
                        不推送
                        <input name="txtEditName" type="radio" value="1" />
                        推送
                    </td>
                </tr>
                <tr>
                    <td class="tb_firsttd">职位设置：</td>
                    <td class="tb_secondtd">
                        <select id="selectProductCategory" name="selectProductCategory" runat="server" class="select01">
                        </select>
                    </td>
                </tr>

                 <tr>
                    <td class="tb_firsttd">工号：</td>
                    <td class="tb_secondtd">
                         <input id="txtEditCardId" name="txtEditCardId" type="text" class="txt01 validate[required]" />
                    </td>
                </tr>
            </table>
        </form>
    </div>

     <%--权限设置--%>
    <div id="dialogSetProduct" class="easyui_dialog" style="padding: 10px 10px;" closed="true">
        <div class="easyui-layout" style="height: 400px; width: 700px; overflow: hidden; border: 0.2px solid #95b8e7; margin: 0px auto;">
            <div region="center" border="false" style="">
                <table id="dataListProduct">
                </table>
            </div>
        </div>
        <input type="hidden" id="idplus" name="idplus" value="" />
        <input type="hidden" id="skus" name="skus" value="" />
    </div>

</body>
</html>


